<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
  <%@ page import="java.net.URLEncoder"   %>
<%
request.setCharacterEncoding("utf-8");
String myitem=request.getParameter("myitem");

String myat=request.getParameter("myat");

String myxy=request.getParameter("myxy");
String myopenid=request.getParameter("myopenid");
if(myitem==null ||myitem.trim().length()==0 ||myat==null||myat.trim().length()==0||myxy==null||myxy.trim().length()==0||myopenid==null){
	response.sendRedirect("err.jsp?msg="+URLEncoder.encode("获取用户信息失败，无法提供服务","utf-8"));
}
myitem=new String(myitem.getBytes("iso-8859-1"),"utf-8");
myat=new String(myat.getBytes("iso-8859-1"),"utf-8");
%>
<!doctype html>
<html>
<head>
	<meta charset="UTF-8">
	<title>订单确认</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection"  content="telephone=no">	
    <link href="../css/css.css" rel="stylesheet"> 
    <link href="../css/easycss.css" rel="stylesheet"/> 
    <script src='../js/jquery-1.8.2.min.js'></script>
	<script src="../js/jquery.mobile-1.2.0.min.js"></script>
	
 <script> 
 var nowpage=1;
 $(document).ready(function(){
 	    //$.mobile.selectmenu.prototype.options.hidePlaceholderMenuItems = false;
		$.mobile.page.prototype.options.addBackBtn = false;
		nowpage=$("#moreshop").val();		
		//当“换一家”按钮被单击时取出符合条件的另一家店铺
		$("#moreshop").click(function(){
			nowpage=$("#moreshop").val();	
			$.ajax({ 
			type:"GET", 
			url:"../nextshop",
			data:{myxy:"<%=myxy%>",page:nowpage,myitem:"<%= myitem%>"}, 
			dataType:"json",
			success:initshop,
			error:function(result){
			  alert("网速有点慢，请重新下单，不要重复点击按钮哦！");
			}
			}); 
		}); 
		
	    });
        //发送ajax请求，获取店铺信息，初始化页面
		$.getJSON("../nextshop",
				{myxy:"<%=myxy%>",page:nowpage,myitem:"<%= myitem%>"},
				initshop); 
		function initshop(data) {			
			//$select=$("#addrlist");	
			//$select.append('<option style="background-color:#eeeeee !important;" value="0">请选择使用过的地址</option>').hide().show();
			
			$.each( data, function( key, val ) {
				if(key=="sid"){
					$("#sid").val(val);//记录当前店铺的编号
				}else if(key=="slabel"){
					$("#s1").html('');
					$("#s1").append('位置: '+val);
				}else if(key=="sname"){
					$("#s1").append("  "+val).hide().show();
				}else if(key=="scape"){
					$("#s2").html('');
					$("#s2").append('经营范围: '+val).hide().show();
				}else if(key=="distance"){
					$("#s3").html('');
					$("#s3").append('距离: '+val).hide().show();
				}else if(key=="count"){
					$("#s4").html('');
					$("#s4").append('最近交易: '+val+'笔').hide().show();
				}else if(key=="per"){
					$("#s5").html('');
					$("#s5").append(val).hide().show();
				}else if(key=="hot"){
					$("#s6").html('');
					$("#s6").append('最多人购买: '+val).hide().show();
				}else if(key=="nextpage"){	
					
					$("#moreshop").val(val);
					
				}				
				else if(key=="err"){
					window.location.href="http://sytj.gigabest.net/easylife/html/err.jsp?msg="+val;
				}
			  }			
            );
			
		}
	
		//完成按钮被单击时		
	    function orderok(){	    	
	    	var myitem=$("#myitem").val();
	    	var myat=$("#myat").val();
	    	var myxy=$("#myxy").val();
	    	var myopenid=$("#myopenid").val();
	    	var sid=$("#sid").val();
	    	
	    	if(myitem==""||myat==""||myxy==""||myopenid==""||sid==""){
	    		alert("信息丢失，请重新购买");
	    	}else{
	    		$.ajax({ 
	    			type:"GET", 
	    			url:"../order",
	    			data:{myxy:myxy,myat:myat,myitem:myitem,openid:myopenid,sid:sid}, 
	    			dataType:"json",
	    			success:nextt,
	    			error:function(result){
	    			  alert(result.status+':'+ result.statusText);
	    			}
	    			}); 
	    	  //document.frmorder.submit();
	    	}
			return false;
	    }
		//处理返回结果
		function nextt(data){
			var sname,phone;
			var flag=true;
			$.each( data, function( key, val ) {
				
				if(key=="sname"){
					sname=val;//记录当前店铺的名称
				}else if(key=="phone"){
					phone=val;
				}			
				else if(key=="err"){
					window.location.href="http://sytj.gigabest.net/easylife/html/err.jsp?msg="+val;
				   flag=false;
					return;
				}
			  });		
			  if(flag) window.location.href="http://sytj.gigabest.net/easylife/html/result.jsp?phone="+phone+"&sname="+sname;
		}
	</script>	
</head>
<body>
<!-- 第二个页面 -->
<div id="page2" data-role="page"> 
	<div data-role="content" class="fund_search">
    	<ul>
            <li class="line2">
            	我要买:<%= myitem %><br/>
            	送到:<%= myat %><br/>
            </li>
            <li>
            <form>
              <input type="hidden" name="myxy" id="myxy" value="<%=myxy %>"/>
              <input type="hidden" name="myat" id="myat" value="<%=myat %>"/>
              <input type="hidden" name="myitem" id="myitem" value="<%=myitem %>"/>
              <input type="hidden" name="myopenid" id="myopenid" value="<%=myopenid %>"/>
              <input type="hidden" name="sid" id="sid" value=""/>
         
            </form>
            	<table width="100%" class="stc_table" cellspacing="0">                
                <tr>
                	<td id="s1" width="75%" class="line1"></td>
                    <td rowspan="4" align="center">
	                    <img width="80px" height="20" src="../images/1_star.jpg"></img>
	                    <img width="80px" height="50"  src="../images/1_logo.jpg"></img>
                    </td>                    
                </tr> 
                <tr>
                	<td class="line1" id="s2" ></td>                    
                </tr> 
                <tr> 
                    <td class="line1" id="s3" ></td>
                    
                </tr>  
                <tr> 
                    <td class="line1" id="s4" ></td>                    
                </tr> 
                <tr> 
                    <td width="75%" class="line1" id="s5" ></td>
                    <td rowspan="2">
                    <a value="1" id="moreshop" data-role="button" class="btnstep1" >
                                                                    换一家
                    </a>
                    </td>                      
                </tr> 
                 <tr> 
                    <td class="line1" id="s6"></td>                    
                </tr> 
            </table>
            </li>
            <li>
            	<div id="ad"><img width="100%" height="100px" src="../images/ad.PNG"></img></div>
            </li>
            <li>
            
                
            	<table width="100%" class="stc_table" cellspacing="2">  
                <tr>
                	<td align="right"> <a href="<%= "order.jsp?openid="+myopenid %>" data-role="button" class="btnstep1"   >
                                                                 上一步
                    </a></td>
                    <td align="left"> <a data-role="button" class="btnstep1"  onclick="orderok()" >
                                                                   完成
                    </a></td>
                </tr>              
            </table>
           
            </li>         
        </ul>
       
    </div>
</div>
</body>
</html>